﻿using System.Data;
using Spire.Xls;

namespace tools.office.freespire
{
    /// <summary>
    /// Free Spire Excel 工具类
    /// </summary>
    public static class FreeSpireExcelTool
    {
        /// <summary>
        /// 读取 Excel 文件转换为 DataTable
        /// </summary>
        /// <param name="filePath">Excel 文件完整路径</param>
        /// <returns>DataTable 实例</returns>
        public static DataTable GetDataTable(string? filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new InvalidOperationException("Excel 文件不存在");
            }

            var wb = new Workbook();
            wb.LoadFromFile(filePath);

            var ws = wb.Worksheets[0];
            return ws.ExportDataTable();
        }
    }
}
